package fuel

import (
	"context"

	"oil-station-backend/internal/svc"
	"oil-station-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetFuelTypesLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetFuelTypesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFuelTypesLogic {
	return &GetFuelTypesLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetFuelTypesLogic) GetFuelTypes() (resp []types.FuelType, err error) {
	// 获取所有油品类型
	fuelTypes, err := l.svcCtx.FuelTypeModel.FindAll()
	if err != nil {
		return nil, err
	}

	// 转换为API响应格式
	var result []types.FuelType
	for _, ft := range fuelTypes {
		result = append(result, types.FuelType{
			Id:    ft.Id,
			Type:  ft.Type,
			Name:  ft.Name,
			Price: ft.Price,
		})
	}

	return result, nil
}